// Anagrams.cpp : Defines the entry point for the console application.
//
//AnagramsMar 
//Given an array of strings, return all groups of strings that are anagrams.

//Note: All inputs will be in lower-case.
//Input ["tea","and","ate","eat","dan"]
//Output ["and","dan","tea","ate","eat"]
#include "stdafx.h"
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;


vector<string> anagrams(vector<string> &strs) 
{
	vector<string> cc;
	map<string, vector<string> > dict;
	vector<string>::iterator st;
	for(st = strs.begin(); st != strs.end(); st++) 
	{
		string key = *st;
		sort(key.begin(), key.end());
		dict[key].push_back(*st);
	}
	
	map<string, vector<string> >::iterator it;
	for(it = dict.begin(); it != dict.end(); it++) 
	{
		if(it->second.size() > 1)
		{
			for(st = it->second.begin(); st != it->second.end(); st++)
			{
				cc.push_back(*st);
			}
		}
	}
	
	return cc;
}

int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

